<?php
namespace App\Http\Controllers\Map;

use App\Service\HwcwService;
use Illuminate\Http\Request;

class HwcwController extends BaseController
{
    //货物仓位

    // 层列表
    public function index(Request $request)
    {
        $cw_id = $request->post('cw_id', 0);
        $res = HwcwService::index($cw_id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    // 选项
    public function getOption()
    {
        $res = HwcwService::getOption();
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    // 详情
    public function getOne(Request $request)
    {
        $id = $request->post('id', '');
        $res = HwcwService::getOne($id);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //入仓
    public function cangIn(Request $request)
    {
        $hw_code = $request->post('hw_code', '');
        $cw_id = $request->post('cw_id', 0);
        $num = $request->post('num', 0);
        $res = HwcwService::cangIn($cw_id, $hw_code, $num);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //减仓
    public function cangDecre(Request $request)
    {
        $id = $request->post('id', 0);
        $num = $request->post('num', 0);
        $res = HwcwService::cangDecre($id, $num);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }

    //加仓
    public function cangIncre(Request $request)
    {
        $id = $request->post('id', 0);
        $num = $request->post('num', 0);
        $res = HwcwService::cangIncre($id, $num);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }
}